﻿Ext.namespace('EHSubmit.Portal');
var tools = [{
    id: 'close',
    handler: function(e, target, panel) {
        panel.ownerCt.remove(panel, true);
    }
}];



//var UserID = store.getAt(0).get("ID");

/// 用户登录信息模块
EHSubmit.Portal.LoginInfo = {
    title: '您好，' + CurrentUser.Name + '老师',
    layout: 'form',
	iconCls:'',
	defaults:{style:'padding:10px 10px 0 10px'},
    items: [
        {
			xtype:'tbtext',
			text:'您的用户ID：' + CurrentUser.ID
        },
		{
			xtype:'tbtext',
			text:'所在学院：' + CurrentUser.Institute
		},
		{
			xtype:'tbtext',
			text:'所属专业：' + CurrentUser.Department
		},
		{
			xtype:'tbtext',
			text:'登录次数：' + CurrentUser.LoginCount
		},
		{
			xtype:'tbtext',
			text:'上次登录时间：' + CurrentUser.LastLoginTime
		},
		{
			xtype:'tbtext',
			style:'text-align:right;padding:10px;',
			text:'<a href="../../Logout.ashx" target="_top">注销</a>'
		}

    ]
}

/// 显示日期模块
EHSubmit.Portal.DateInfo = {
      title: '日历',
//    items: [{
//        xtype:'datepicker',
//        format: 'Y-m-d',
//        style: 'width:100%;height:100%',
//        listeners: {
//            'render': function(dp) {
//                //取得DatePicker的DOM节点的第一个子节点
//                var outerTable = dp.el.dom.firstChild;
//                //取得DatePicker的顶部导航条
//                var tbar = outerTable.firstChild.childNodes[0];
//                //取得DatePicker的主体
//                var main = outerTable.firstChild.childNodes[1];
//                //取得DatePicker底部工具条
//                var bbar = outerTable.firstChild.childNodes[2];

//                var innerTable = main.firstChild.firstChild;
//                //
//                var thead = innerTable.firstChild;
//                //使用行内样式修改
//                outerTable.style.width = '100%';
//                outerTable.style.height = '100%';
//                //以下为解决DatePicker变形
//                tbar.style.height = '30px';
//                bbar.style.height = '30px';
//                innerTable.style.height = '100%';
//                thead.firstChild.style.height = '20px';
//            }
//        }
//    }]
      html: '<div>&nbsp;&nbsp;&nbsp;&nbsp;<embed src="' + EHSubmit.appRoot + 'images/calendar.swf" Width="250px" Height="350px" type="application/x-shockwave-flash" ></embed></div>'
}

// 显示天气模块
//EHSubmit.Portal.WeatherInfo = {
//    title: '天气',
////    html: '今天气温：' + Weather.Temperature + '<br/>天气：' + Weather.Weather
////            + '<br/>风向：' + Weather.Wind         //<img src='images/login_head.jpg'/>
//    html: '<table><tr><th>今天气温：' + Weather.Temperature + '<br/>天气：' + Weather.Weather
//            + '<br/>风向：' + Weather.Wind + '</th><th background="' + Weather.Photo + '"></th></tr></table>',
//    items:[{
//        xtype: 'panel',
//        html:'<img src="'+Weather.Photo+'"/>'
//    }]
//}
//EHSubmit.Portal.WeatherInfo = {
//    title:'天气',
//    height:200
//}


EHSubmit.Portal.WeatherInfo = {
    title: '天气',
    listeners: {
        render: function() {
            var store = new Ext.data.JsonStore({
                url: EHSubmit.ajaxRoot + 'PortletHandler.ashx?op=GetWeather',
                //autoLoad: true,
                root: 'data',
                fields: ['ImageSrc', 'Temperature', 'Weather', 'Wind']
            });
            store.load();
            //store.load({ callback: function() { alert(store.getCount()) } });
            store.on('load', request, this, true);
            function request() {
                ImageSrc = store.getAt(0).get("ImageSrc");
                Temperature = store.getAt(0).get("Temperature");
                Weather = store.getAt(0).get("Weather");
                Wind = store.getAt(0).get("Wind");
                document.getElementById("WeatherDIV").innerHTML = "<style>.center{text-align:center;}.center a {color: #000000;text-decoration: none;}a:hover {color: #000000;text-decoration: underline}</style><table class='center' style='font-size:10pt;color'><tr><th><img src='" + EHSubmit.appRoot + ImageSrc +
                                                                    "'></img></th><th align='left'>今天气温：" + Temperature + " <br>天气：" + Weather + "<br>风向： " + Wind + "</th></tr></table><br><br><br>";
            }

        }
    },
    //html: '<iframe src="'+EHSubmit.appRoot+'View/Shared/Weather.aspx'+'" frameborder=0></iframe>'
    html: '<div id=WeatherDIV><br>&nbsp;&nbsp;等待加载...<br><br></div>'
}

///校内动态模块
EHSubmit.Portal.CampusNews = {
    title:'校内动态',
    //tools:tools,
    html: '<div><br><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.wutnews.net/" target="_blank"><img src="' + EHSubmit.appRoot + 'images/wutnews_logo.jpg" alt="新闻经纬"></img></a>' +
          '<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.wutyouth.net/news2008/index.aspx" target="_blank"><img src="' + EHSubmit.appRoot + 'images/lgqn_logo.jpg" alt="理工青年"></img></a>' +
          '<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://stuplaza.whut.edu.cn/" target="_blank"><img src="' + EHSubmit.appRoot + 'images/xggc_logo.jpg" alt="学工广场"></img></a><br><br><br></div>'
}

///综合消息模块



EHSubmit.Portal.Messages = {
    title: '消息提示',
    listeners: {
        render: function() {
            var store = new Ext.data.JsonStore({
                url: EHSubmit.ajaxRoot + 'PortletHandler.ashx?op=GetMessage',
                //autoLoad: true,
                root: 'data',
                fields: ['UserNum', 'AdminNum', 'HomeWorkNum']
            });
            store.load();
            //store.load({ callback: function() { alert(store.getCount()) } });
            store.on('load', request, this, true);
            function request() {
                UserNum = store.getAt(0).get("UserNum");
                AdminNum = store.getAt(0).get("AdminNum");
                HomeWorkNum = store.getAt(0).get("HomeWorkNum");

                if (HomeWorkNum == 0) {
                    document.getElementById("MessageDIV").innerHTML = "<style>.center{text-align:center;}.center a {color: #000000;text-decoration: none;}a:hover {color: #000000;text-decoration: underline}</style><table class='center' style='font-size:10pt;color'><tr>&nbsp;</tr><tr><th>&nbsp;&nbsp;<img src='" +
                                                                    EHSubmit.appRoot + "images/HomeWork_1.gif'></img><a href='#' onclick='mainPanel.showTab(EHSubmit.MessageBox.Inbox.form);'>您有<B>" + UserNum + "</B>条用户消息</a></th></tr>" +
                                                                  "<tr><th>&nbsp;&nbsp;<img src='" + EHSubmit.appRoot + "images/HomeWork_1.gif'></img><a href='#' onclick='mainPanel.showTab(EHSubmit.MessageBox.Inbox.form);'>您有<B>" + AdminNum + "</B>条系统消息</a></th></tr>" +
                                                                  "</table><br><br><br>";
                }
                else {
                    document.getElementById("MessageDIV").innerHTML = "<style>.center{text-align:center;}.center a {color: #000000;text-decoration: none;}a:hover {color: #000000;text-decoration: underline}</style><table class='center' style='font-size:10pt;color'><tr>&nbsp;</tr><tr><th>&nbsp;&nbsp;<img src='" +
                                                                    EHSubmit.appRoot + "images/HomeWork_1.gif'></img><a href='#' onclick='mainPanel.showTab(EHSubmit.MessageBox.Inbox.form);'>您有<B>" + UserNum + "</B>条用户消息</a></th></tr>" +
                                                                  "<tr><th>&nbsp;&nbsp;<img src='" + EHSubmit.appRoot + "images/HomeWork_1.gif'></img><a href='#' onclick='mainPanel.showTab(EHSubmit.MessageBox.Inbox.form);'>您有<B>" + AdminNum + "</B>条系统消息</a></th></tr>" +
                                                                  "<tr><th>&nbsp;&nbsp;<img src='" + EHSubmit.appRoot + "images/HomeWork_1.gif'></img><a href='#' onclick='mainPanel.showTab(EHSubmit.Work.MarkingList.Tab);'>您有<B>" + HomeWorkNum + "</B>个待批改作业</a></th></tr></table><br><br><br>";
                }
            }

        }
    },
    html: '<div id = MessageDIV><br>&nbsp;&nbsp;等待连接...<br><br></div>'
}

/// 提交作业快捷方式模块
EHSubmit.Portal.QuickSubmit = {
    title: '提交作业',
    //tools:tools,
    html: '<br/><br/<br/><br/><br/><br/><br/>'
}

//// portal显示三列,左列
EHSubmit.Portal.LeftColumn  = {
    columnWidth: .33,
    style: 'padding:10px 0 10px 10px',
    defaults :{
     	tools: tools,
        style: 'margin: 5px 0 5px 0'
        //width: 150
    },
    items: [EHSubmit.Portal.LoginInfo, EHSubmit.Portal.WeatherInfo]
}




//// portal显示三列,中列
EHSubmit.Portal.MidColumn = {
    columnWidth: .33,
    style: 'padding:10px 0 10px 10px',
    defaults: {
        tools: tools,
        style: 'margin: 5px 0 5px 0'
    },
    items: [EHSubmit.Portal.DateInfo]
}

//// portal显示三列,右列
EHSubmit.Portal.RightColumn = {
    columnWidth: .33,
    style: 'padding:10px',
    defaults: {
        tools: tools,
        style: 'margin: 5px 0 5px 0'
    },
    items: [EHSubmit.Portal.Messages,EHSubmit.Portal.CampusNews]
}

var portal = {
    xtype:'portal',
    margins: '0',
    border:false,
    items: [EHSubmit.Portal.LeftColumn, EHSubmit.Portal.MidColumn, EHSubmit.Portal.RightColumn]
};